package com.irdstudio.tdp.console.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.tdp.console.service.facade.IsrvInoutInfoService;
import com.irdstudio.tdp.console.dao.IsrvInoutInfoDao;
import com.irdstudio.tdp.console.dao.domain.IsrvInoutInfo;
import com.irdstudio.tdp.console.service.vo.IsrvInoutInfoVO;
import com.irdstudio.sdk.beans.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 内部模型输入输出				<p>
 * @author zjj
 * @date 2021-03-16
 */
@Service("isrvInoutInfoServiceImpl")
public class IsrvInoutInfoServiceImpl implements IsrvInoutInfoService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(IsrvInoutInfoServiceImpl.class);

	@Autowired
	private IsrvInoutInfoDao isrvInoutInfoDao;
	
	/**
	 * 新增操作
	 */
	public int insertIsrvInoutInfo(IsrvInoutInfoVO inIsrvInoutInfoVo) {
		logger.debug("当前新增数据为:"+ inIsrvInoutInfoVo.toString());
		int num = 0;
		try {
			IsrvInoutInfo isrvInoutInfo = new IsrvInoutInfo();
			beanCopy(inIsrvInoutInfoVo, isrvInoutInfo);
			num = isrvInoutInfoDao.insertIsrvInoutInfo(isrvInoutInfo);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	@Override
	public int insertIsrvInoutInfos(List<IsrvInoutInfo> isrvInoutInfos) {
		logger.debug("批量新增数据");
		int num = 0;
		try {
			num = isrvInoutInfoDao.insertIsrvInoutInfos(isrvInoutInfos);
		}catch (Exception e){
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(IsrvInoutInfoVO inIsrvInoutInfoVo) {
		logger.debug("当前删除数据条件为:"+ inIsrvInoutInfoVo);
		int num = 0;
		try {
			IsrvInoutInfo isrvInoutInfo = new IsrvInoutInfo();
			beanCopy(inIsrvInoutInfoVo, isrvInoutInfo);
			num = isrvInoutInfoDao.deleteByPk(isrvInoutInfo);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inIsrvInoutInfoVo +"删除的数据条数为"+ num);
		return num;
	}

	@Override
	public int deleteByAppModelId(IsrvInoutInfoVO isrvInoutInfoVo) {
		logger.debug("当前删除数据条件为:"+ isrvInoutInfoVo);
		int num = 0;
		try {
			IsrvInoutInfo isrvInoutInfo = new IsrvInoutInfo();
			beanCopy(isrvInoutInfoVo, isrvInoutInfo);
			num = isrvInoutInfoDao.deleteByAppModelId(isrvInoutInfo);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ isrvInoutInfoVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(IsrvInoutInfoVO inIsrvInoutInfoVo) {
		logger.debug("当前修改数据为:"+ inIsrvInoutInfoVo.toString());
		int num = 0;
		try {
			IsrvInoutInfo isrvInoutInfo = new IsrvInoutInfo();
			beanCopy(inIsrvInoutInfoVo, isrvInoutInfo);
			num = isrvInoutInfoDao.updateByPk(isrvInoutInfo);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inIsrvInoutInfoVo +"修改的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateAppModelId(IsrvInoutInfoVO inIsrvInoutInfoVo) {
		logger.debug("当前修改数据为:"+ inIsrvInoutInfoVo.toString());
		int num = 0;
		try {
			IsrvInoutInfo isrvInoutInfo = new IsrvInoutInfo();
			beanCopy(inIsrvInoutInfoVo, isrvInoutInfo);
			num = isrvInoutInfoDao.updateByAppModelId(isrvInoutInfo);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inIsrvInoutInfoVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public IsrvInoutInfoVO queryByPk(IsrvInoutInfoVO inIsrvInoutInfoVo) {
		
		logger.debug("当前查询参数信息为:"+ inIsrvInoutInfoVo);
		try {
			IsrvInoutInfo queryIsrvInoutInfo = new IsrvInoutInfo();
			beanCopy(inIsrvInoutInfoVo, queryIsrvInoutInfo);
			IsrvInoutInfo queryRslIsrvInoutInfo = isrvInoutInfoDao.queryByPk(queryIsrvInoutInfo);
			if (Objects.nonNull(queryRslIsrvInoutInfo)) {
				IsrvInoutInfoVO outIsrvInoutInfoVo = beanCopy(queryRslIsrvInoutInfo, new IsrvInoutInfoVO());
				logger.debug("当前查询结果为:"+ outIsrvInoutInfoVo.toString());
				return outIsrvInoutInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<IsrvInoutInfoVO> queryAllOwner(IsrvInoutInfoVO isrvInoutInfoVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<IsrvInoutInfoVO> list = null;
		try {
			List<IsrvInoutInfo> isrvInoutInfos = isrvInoutInfoDao.queryAllOwnerByPage(isrvInoutInfoVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ isrvInoutInfos.size());
			pageSet(isrvInoutInfos, isrvInoutInfoVo);
			list = (List<IsrvInoutInfoVO>) beansCopy(isrvInoutInfos, IsrvInoutInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<IsrvInoutInfoVO> queryAllCurrOrg(IsrvInoutInfoVO isrvInoutInfoVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<IsrvInoutInfo> isrvInoutInfos = isrvInoutInfoDao.queryAllCurrOrgByPage(isrvInoutInfoVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+isrvInoutInfos.size());
		List<IsrvInoutInfoVO> list = null;
		try {
			pageSet(isrvInoutInfos, isrvInoutInfoVo);
			list = (List<IsrvInoutInfoVO>) beansCopy(isrvInoutInfos, IsrvInoutInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<IsrvInoutInfoVO> queryAllCurrDownOrg(IsrvInoutInfoVO isrvInoutInfoVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<IsrvInoutInfo> isrvInoutInfos = isrvInoutInfoDao.queryAllCurrDownOrgByPage(isrvInoutInfoVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ isrvInoutInfos.size());
		List<IsrvInoutInfoVO> list = null;
		try {
			pageSet(isrvInoutInfos, isrvInoutInfoVo);
			list = (List<IsrvInoutInfoVO>) beansCopy(isrvInoutInfos, IsrvInoutInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
}
